package com.wuyou.controller;

import com.wuyou.domain.Result;
import com.wuyou.domain.po.AdvDayPrice;
import com.wuyou.service.IAdvDayPriceService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘雷雨
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/advDayPrice")
@Api(value = "广告天数价格接口")
public class AdvDayPriceController {

    @Autowired
    private IAdvDayPriceService advDayPriceService;

    /**
     * 查询所有广告天数价格信息
     * @return
     */
    @GetMapping
    public Result findAdvDayPrice() {
        try {
            return Result.OK().setData(advDayPriceService.list());
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }

    /**
     * 根据广告天数价格ID 逻辑删除一条广告价格信息
     * @param advPriceId = 广告天数价格ID
     * @return
     */
    @DeleteMapping
    public Result deleteAdvDayPriceById(@RequestParam Long advPriceId) {

        try {
            return Result.OK().setData(advDayPriceService.removeById(advPriceId));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }

    /**
     * 根据广告天数价格ID 修改一条广告价格信息
     * @param advDayPrice = 广告天数价格实体
     * @return
     */
    @PostMapping
    public Result updateAdvDayPrice(@RequestBody AdvDayPrice advDayPrice) {

        try {
            return Result.OK().setData(advDayPriceService.updateById(advDayPrice));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }

    /**
     * 根据广告天数价格ID 查询一条广告价格信息
     * @param advPriceId  = 广告天数价格ID
     * @return
     */
    @PostMapping("findAdvDayPriceById")
    public Result findAdvDayPriceById(@RequestParam Long advPriceId) {
        try {
            return Result.OK().setData(advDayPriceService.getById(advPriceId));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }
}
